package com.lei.ajax.dao.impl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBC {
	private static String user = "student";
	private static String password = "student123";
	
	private static String className = "com.mysql.jdbc.Driver";
	// private String className = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
	private static String url = "jdbc:mysql://47.98.129.170:3306/student?useUnicode=true&characterEncoding=utf8";

	public static Connection getConn() {
		try {
			Class.forName(className);
			return DriverManager.getConnection(url, user, password);
		} catch (SQLException | ClassNotFoundException e) {
			e.printStackTrace();
		}

		return null;
	}


	public static void close(ResultSet rs, Statement state, Connection conn) {
		if (rs != null) {
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			rs = null;
		}
		if (state != null) {
			try {
				state.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			state = null;
		}
		if (conn != null) {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			conn = null;
		}
	}

	public static void main(String[] args) {
		System.out.println(getConn());
	}
}
